package com.view.pages.worldtown.rooms
{
	import flash.display.MovieClip;
	import flash.events.NetStatusEvent;
	import flash.media.Video;
	import flash.net.NetConnection;
	import flash.net.NetStream;
	
	import org.papervision3d.materials.VideoStreamMaterial;
	import org.papervision3d.objects.parsers.Collada;
	import org.papervision3d.objects.primitives.Plane;

	public class Room1 extends BaseRoom
	{
		private var $room:Collada;
		
		private var $doorsMC:MovieClip;
		
		
		//VIDEO
		private var $connection:NetConnection;
		private var $stream:NetStream;
		private var $video:Video;
		private var $movie:Plane;
		
		private var $vm:VideoStreamMaterial;
		
		
		public function Room1(_loadedXml:Object,_rSettings:Object,_loadedImages:Object)
		{
			super(_loadedXml,_rSettings,_loadedImages);
			init();
		}
		private function init():void
		{
			$room = new Collada($_loadedXml.room1);
			addChild($room);
			
			
			/*var $video:SimpleVideo = new SimpleVideo("2008_07_08_FlexTest/video/01.flv");
			$video.load();
			//$video.play();
			//addChild($video);*/
			
			$connection = new NetConnection();
	        $connection.connect(null);
	        $stream = new NetStream($connection);
	        $stream.addEventListener(NetStatusEvent.NET_STATUS, onStatus);
	        $stream.client = new Object();
	        $video = new Video(500, 300);
	        $stream.play("2008_07_08_FlexTest/video/04.flv");
	        $video.attachNetStream($stream);
	        $stream.pause();
			//var $video:VideoLoop = new VideoLoop("2008_07_08_FlexTest/video/02.flv");
			//addChild($vid);
			
			$vm = new VideoStreamMaterial($video,$stream);
			
			
			//$vm.stream.p
			$movie = new Plane($vm,1000,600,4,4);
			$movie.y = 1000;
			$movie.z = 14000;
			addChild($movie);
			
			
		}
		private function onStatus(nse:NetStatusEvent):void
		{
			if (nse.info.code == "NetStream.Play.Stop") {
				nse.target.seek(0);
				$vm.stream.play("2008_07_08_FlexTest/video/04.flv");
			}
		}
		override public function disableRoom():void
		{
			//$stream.close();
			$stream.pause();
			//trace($movie.materials[0]);
		}
		override public function enableRoom():void
		{
			$stream.resume();
		}
	}
}